package com.dragon.client.controller.avttendance;

import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.common.model.Update;
import com.dragon.logical.service.avttendance.IArrangePeriodService;
import com.dragon.repository.domain.dto.ArrangePeriodDTO;
import com.dragon.repository.domain.vo.ArrangePeriodVO;
import com.dragon.repository.entity.ArrangePeriod;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 考勤配置时段 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-07-31
 */
@RestController
@RequestMapping("arrangePeriod")
@Api(tags = "考勤时间")
public class ArrangePeriodController {

    @Autowired
    IArrangePeriodService service;

    @GetMapping("list")
    @ApiOperation("根据主配置id获取list")
    public ResponseData<List<ArrangePeriodDTO>> list(@ApiParam(name = "arrangeId", value = "主配置id", required = true, type = "int")
                                                     @RequestParam(required = true) Integer arrangeId){
        List<ArrangePeriod> periods = service.showList(arrangeId);
        return ResponseData.success(ArrangePeriodDTO.convertList(periods));

    }

    @PostMapping("add")
    @ApiOperation("添加")
    public ResponseData addPeriod(@ApiParam(name = "arrangeId", value = "配置id",required = true,type = "int") @RequestParam Integer arrangeId,
                                  @RequestBody @Validated(Insert.class) ArrangePeriodVO vo){
        service.periodAdd(arrangeId,ArrangePeriodVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("update")
    @ApiOperation("修改")
    public ResponseData updatePeriod(@RequestBody @Validated(Update.class) ArrangePeriodVO vo){
        service.periodUpdate(ArrangePeriodVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("delete")
    @ApiOperation("删除")
    public ResponseData deletePeriod(@ApiParam(name = "id", value = "主键id", required = true, type = "int")
                                     @RequestParam Integer id){
        service.periodDelete(id);
        return ResponseData.success();
    }


}
